package cn.yhjz.common;

import lombok.Data;

/**
 * ajax结果的封装
 */
@Data
public class AjaxResponse<T> {
    private int code;
    private boolean success;
    private String msg;
    private String errMsg;
    private T data;

    public static AjaxResponse success() {
        return success("success");
    }

    public static AjaxResponse success(String msg) {
        return success(msg, null);
    }

    public static AjaxResponse success(Object data) {
        return success("success", data);
    }

    public static AjaxResponse success(String msg, Object data) {
        AjaxResponse response = new AjaxResponse();
        response.code = 200;
        response.msg = msg;
        response.data = data;
        response.success = true;
        return response;
    }

    public static AjaxResponse fail(String errMsg) {
        return fail(500, errMsg);
    }

    public static AjaxResponse fail(int code, String errMsg) {
        AjaxResponse response = new AjaxResponse();
        response.code = code;
        response.errMsg = errMsg;
        response.success = false;
        return response;
    }
}
